<#assign tit><#if _oper='add'>新增<#else>修改</#if>营销活动</#assign>
<@page.html title=tit>
<script type="text/javascript" src="${_appPath!}/js/cal.js"></script>
<script type="text/javascript">
  var sl_cts = '<select style="width:200px;"><option value=""></option><#if cardTypeList??><#list cardTypeList as t><option value="${t.code}">${t.code} - ${t.chName}</option></#list></#if></select>';
  var ss_del = '<img src="${_appPath!}/images/del.png" onclick="deli(this);" style="cursor:pointer;"/>';

  function deli(e) {
    var tr = e.parentNode.parentNode;
    var aid = tr.getAttribute("aid");
    if(aid)
      tr.style.display = "none";
    else
      tr.parentNode.deleteRow(tr.rowIndex);
  }
  function addct() {
    var tb = getEl("tb_card");
    if(!tb) return;
    var tr = tb.insertRow(-1);
    tr.className = (tb.rows.length%2?"line1":"line2");
    var td = tr.insertCell(-1);
    td.className = "left";
    td.style.width = "205px";
    td.innerHTML = sl_cts;
    td = tr.insertCell(-1);
    td.innerHTML = '<input type="text" value="" size="8" maxlength="8">';
    td = tr.insertCell(-1);
    td.innerHTML = ss_del;
    tb.parentNode.scrollTop = 9999;
  }

  function save(fm) {
    if(!dotbd(fm.cards, "tb_card", ["卡种","价格"])) return false;
    return post(fm);
  }
  function dotbd(ipt, tbid, cl) {
    var tb = getEl(tbid);
    if(!tb) return false;
    var i, j, aid, el, ss, tr, arr = [];
    for(j=0; j<tb.rows.length; j++) {
      tr = tb.rows[j];
      aid = tr.getAttribute("aid");
      if(tr.style.display=="none") {
        if(aid) arr.push(aid+",-");
      } else {
        for(i=0; i<cl.length; i++) {
          el = tr.cells[i].firstChild;
          if(el.tagName=="INPUT" && (el.type=="radio" || el.type=="checkbox")) {
            continue;
          }
          if(el.value=="" && cl[i]!="") {
            window.alert("请"+(el.tagName=="SELECT"?"选择":"输入")+cl[i]);
            try {el.focus();} catch(e) {}
            return false;
          }
        }
        ss = aid?aid:"";
        for(i=0; i<cl.length; i++) {
          ss += ",";
          el = tr.cells[i].firstChild;
          if(!(el.tagName=="INPUT" && (el.type=="radio" || el.type=="checkbox") && !el.checked))
            ss += el.value;
        }
        arr.push(ss);
      }
    }
    ipt.value = arr.join("|");
    return true;
  }
</script>
<div style="width:750px;">

  <form id="fm_input" method="post" action="<#if _oper='add'>_add<#else>_edit</#if>" onsubmit="return save(this);">
    <input type="hidden" name="promotionId" value="${promotion.promotionId!}"><input type="hidden" name="cards" value="">
    <div class="kbox">
      <div style="width:350px; float:left;">
        <table class="input">
          <tr>
            <th width="25%">活动名称</th>
            <td width="75%"><input type="text" name="chName" value="${promotion.chName!}" req="名称" size="26" maxlength="50"><span class="require">*</span></td>
          </tr>
          <tr>
            <th>启用日期</th>
            <td><input type="text" class="date" name="activeTime" value="${promotion.activeTime!}" onclick="cal(this);" size="10" maxlength="10"></td>
          </tr>
          <tr>
            <th>结束时间</th>
            <td><input type="text" class="date" name="inactiveTime" value="${promotion.inactiveTime!}" onclick="cal(this);" size="10" maxlength="10"></td>
          </tr>
          <tr>
            <th>状态</th>
            <td><input type="radio" name="status" id="enable_1" value="1"<#if promotion.status=1> checked</#if>><label for="enable_1">正常</label>
              <input type="radio" name="status" id="enable_2" value="2"<#if promotion.status!=1> checked</#if>><label for="enable_2">停用</label></td>
          </tr>
          <tr>
            <th>备注</th>
            <td><textarea name="note" cols="30" rows="3">${promotion.note!}</textarea></td>
          </tr>
        </table>

        <div class="lsinfo">卡种价格</div>
        <table class="list">
          <tr>
            <th width="60%">卡种</th>
            <th width="30%">价格</th>
            <th></th>
          </tr>
        </table>
        <div style="max-height:290px; overflow-y:auto; overflow-x:hidden;">
          <table id="tb_card" class="list"><#if cardList??><#list cardList as c>
            <tr<#if c_index%2==1> class="line2"<#else> class="line1"</#if> aid="${c.autoId}">
              <td class="left"><select style="width:200px;"><option value=""></option><#if cardTypeList??><#list cardTypeList as t><option value="${t.code}" <#if c.cardType=t.code>selected</#if>>${t.code} - ${t.chName}</option></#list></#if></select></td>
              <td><input type="text" value="${c.price}" size="8" maxlength="8"></td>
              <td><img src="${_appPath!}/images/del.png" onclick="deli(this);" style="cursor:pointer;"/></td>
            </tr></#list></#if>
          </table>
        </div>
        <div><a href="javascript:addct();" class="addline">增加一行</a></div>

      </div>

      <div style="width:320px; float:left; margin-left:20px;">
        <div class="lsinfo" style="margin-top:2px;">可售门店</div>
        <table class="list">
          <tr>
            <th width="13%">选择</th>
            <th width="30%">编号</th>
            <th width="45%" class="left">名称</th>
            <th width="10%"></th>
          </tr>
        </table>
        <div style="height:232px; overflow-y:auto;">
          <table class="list">
            <#if shopList??><#list shopList as t>
            <tr<#if t_index%2==1> class="line2"<#else> class="line1"</#if>>
              <td class="no"><input type="checkbox" name="shops" value="${t.code}" <#if t.status?? && t.status=1> checked</#if>/></td>
              <td>${t.code}</td>
              <td class="left">${t.chName}</td>
            </tr></#list></#if>
          </table>
        </div>

        <div class="lsinfo">选择礼品</div>
        <table class="list">
          <tr>
            <th width="13%">选择</th>
            <th width="25%">编号</th>
            <th width="50%" class="left">名称</th>
            <th width="10%"></th>
          </tr>
        </table>
        <div style="height:232px; overflow-y:auto;">
          <table class="list">
            <#if productList??><#list productList as t>
              <tr<#if t_index%2==1> class="line2"<#else> class="line1"</#if>>
                <td class="no"><input type="checkbox" name="prods" value="${t.productCode}" <#if t.status?? && t.status=1> checked</#if>/></td>
                <td>${t.productCode}</td>
                <td class="left">${t.productName}</td>
              </tr></#list></#if>
          </table>
        </div>

      </div>
      <div class="clear"></div>

    </div>
    <div class="button"><input type="submit" value="提 交"></div>
  </form>
</div>
</@page.html>